package net.zdreamer.shunyi.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import net.zdreamer.shunyi.R;
import net.zdreamer.shunyi.adapter.GuangChangAdapter;
import net.zdreamer.shunyi.myview.XListView;
import net.zdreamer.shunyi.utils.ListUtils.GuangChangInfos;


public class TJWJActivity extends Activity implements AdapterView.OnItemClickListener, XListView.IXListViewListener {
    private RelativeLayout title;
    private ImageView leftimg;
    private TextView titlecontent;
    private XListView listView;
    private GuangChangAdapter madpter;
    private Handler mHandler;
    private Intent intent;

    private int start = 0;
    private static int refreshCnt = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tjwj);
        init();
        mHandler = new Handler();
    }

    private void init() {
        leftimg = (ImageView) findViewById(R.id.leftimg);
        title = (RelativeLayout) findViewById(R.id.title_item);
        titlecontent = (TextView) findViewById(R.id.title_content);
        title.setBackgroundResource(R.drawable.newsbiaoti);
        leftimg.setImageResource(R.drawable.backimg);
        titlecontent.setText("问卷");
        titlecontent.setTextColor(getResources().getColor(R.color.white));


        leftimg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TJWJActivity.this.finish();
            }
        });

        listView = (XListView) findViewById(R.id.wenjuanlist);
        listView.setOnItemClickListener(this);
        listView.setXListViewListener(this);
        listView.setPullLoadEnable(true);

        GuangChangInfos guangChangInfos = new GuangChangInfos();
        madpter = new GuangChangAdapter(this, guangChangInfos.guangChangInfos, R.layout.guangchamg_item);
        listView.setAdapter(madpter);
        listView.setOnItemClickListener(this);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        intent = new Intent(this, WJDC1Activity.class);
        startActivity(intent);
    }

    private void onLoad() {
        listView.stopRefresh();
        listView.stopLoadMore();
        listView.setRefreshTime("刚刚");
    }

    @Override
    public void onRefresh() {
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                start = ++refreshCnt;
                onLoad();
            }
        }, 500);
    }

    @Override
    public void onLoadMore() {
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                onLoad();
            }
        }, 2000);
    }
}
